//
//  WithdrawViewController.m
//  YYPHSpeedJump
//
//  Created by sujiang on 16/1/8.
//  Copyright © 2016年 sujiang. All rights reserved.
//

#import "WithdrawViewController.h"

@interface WithdrawViewController ()<UIAlertViewDelegate>

@end

@implementation WithdrawViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"提现";
    // Do any additional setup after loading the view from its nib.
    self.tipsLb.text = @"1.提现至最近用于支付的账号中\n2.系统赠送的金钱无法进行提现操作。";
    self.displayMoneyLb.text = self.money;
    
}

- (IBAction)sureWithDrawBtn:(id)sender {
    // 	/user.do?cmd=withdraw&u=x&money=123.123
    if (self.inputMoneyTF.text.floatValue > self.money.floatValue) {
        NSLog(@"%f", self.money.floatValue);
        [Tools showAlert:@"请输入正确提现金额!"];
        return;
    }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提现" message:@"你确定要进行提现操作吗?" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
    [alert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [self.view endEditing:YES];
    if (buttonIndex == 0) {
        NSString *string = [NSString stringWithFormat:@"%@%@", kBaseUrl, @"/user.do?cmd=withdraw"];
        NSDictionary *dict = @{@"u":[[NSUserDefaults standardUserDefaults] objectForKey:@"user_id"], @"money":self.inputMoneyTF.text};
        [NetworkHandle getInfoWithUrl:string dictionary:dict success:^(NSDictionary *dictionary) {
            if ([dictionary[@"code"] integerValue] == 200) {
                self.displayMoneyLb.text = [NSString stringWithFormat:@"%.2f", self.displayMoneyLb.text.floatValue - self.inputMoneyTF.text.floatValue];
                
                UIViewController *vc = [[UIViewController alloc]init];
                UILabel *baseLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, kScreenWidth-10, 30)];
                [vc.view addSubview:baseLabel];
                baseLabel.text =@"提现申请已提交";
                UIImageView *ImgView= [[UIImageView alloc]initWithFrame:CGRectMake(10, 35, 21, 21)];
                [vc.view addSubview:ImgView];
                ImgView.image = [UIImage imageNamed:@"rmb"];
                UILabel *promptLable =[[UILabel alloc]initWithFrame:CGRectMake(40, 30, kScreenWidth-40, 30)];
                [vc.view addSubview:promptLable];
                promptLable.text = dictionary[@"message"];
                promptLable.font = [UIFont systemFontOfSize:12];
                [self.navigationController pushViewController:vc animated:NO];
            }
        }];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
